package library.web.servlet.page;

import library.domain.Book;
import library.persistence.dao.BookDao;
import library.persistence.impl.BookDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

public class BookHomePageServlet extends HttpServlet {

    public static final String BOOK_HOME_PAGE = "/WEB-INF/jsp/bookHomePage.jsp";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BookDao bookDao = new BookDaoImpl();
        HttpSession session = req.getSession();

        List<Book> bookList= bookDao.getAllBook();
        session.setAttribute("bookList",bookList);

        req.getRequestDispatcher(BOOK_HOME_PAGE).forward(req,resp);

    }

}
